package com.inoneone.youba.mcht.conf;

import com.inoneone.youba.mcht.dao.po.Merchant;
import com.inoneone.youba.mcht.enums.ErrorCode;
import com.inoneone.toolkit.exception.BusinessRuntimeException;
import com.inoneone.youba.mcht.util.CommonUtil;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


public class LoginFilter extends HandlerInterceptorAdapter {
    @Override
    public boolean preHandle(HttpServletRequest httpServletRequest, HttpServletResponse response, Object o) throws Exception {
        Object obj = CommonUtil.getSession(httpServletRequest.getSession());
        if (obj == null || !(obj instanceof Merchant)) {
            throw new BusinessRuntimeException(ErrorCode.NOT_LOGIN);
        }
        return true;
    }
}
